const base_url = 'https://paole.hebeixiaoyu.cn/run';
// const base_url = 'http://localhost:1949/run';
const timeout = 5000;
export default (params) => {
	let url = params.url;
	let method = params.method || "get";
	let data = params.data || {};
	let token = uni.getStorageSync("userInfo")
	console.log(uni.getStorageSync("token"))
	let header = {
		'Content-Type': 'application/json;charset=UTF-8',
		'Token': '',
		"Authorization": `Bearer ${uni.getStorageSync("token")}`,
		"Authori-zation": uni.getStorageSync("token")
	}
	if (method == "post") {
		header = {
			'Content-Type': 'multipart/form-data'
		};
	}
	header.Token = uni.getStorageSync("token").token
	return new Promise((resolve, reject) => {
		uni.request({
			url: base_url + url,
			method: method,
			header: header,
			data: data,
			timeout,
			success(response) {
				const res = response
				if (res.statusCode == 200) {
					resolve(res.data);
				} else if (res.statusCode == 401) {
					uni.showModal({
						title: '提示',
						content: res.data.msg,
						showCancel: false,
						success: () => {
							uni.removeStorageSync('token')
							uni.removeStorageSync('userInfo')
							uni.switchTab({
								url: '/pages/mine/mine'
							})
						}
					})
				} else {

				}
			},
			fail(err) {
				reject(err);
			},
			complete() {}
		});
	}).catch(() => {});
};